//路由配置
import { createRouter, createWebHistory } from 'vue-router';
import Login from '@/components/Login.vue';//登录
import UserHome from '@/views/UserHome.vue';//普通用户首页
import HomeView from "@/views/HomeView.vue";//主页
import AdminHome from '@/views/AdminHome.vue';//管理员用户首页
import DemoServlet from '@/views/DemoServlet.vue';
import Chart from '@/components/OrdinaryUsers/Chart.vue';//图表
import Borrow from '@/components/OrdinaryUsers/BooksList.vue';//借书页面
import UserMyInfo from "@/components/OrdinaryUsers/UserMyInfo.vue";//普通用户个人中心
import AllRecords from '@/components/OrdinaryUsers/AllRecords.vue';//全部借阅记录
import Books from '@/components/AdminUser/BooksManagenment.vue';//管理员图书管理界面
import AdminMyInfo from '@/components/AdminUser/AdminMyInfo.vue';//管理员个人中心
import UserManagement from '@/components/AdminUser/UserManagement.vue';//用户管理
import BorrowRecords from "@/components/AdminUser/BorrowRecords.vue";//借阅管理
import Test from "@/views/Test.vue";
import Enroll from "@/components/Enroll.vue";

const routes = [
    {
        path: '/',
        redirect: '/login' // 页面重定向到登录界面
    },
    {
        path: '/login',
        name: 'Login',
        component: Login,
    },
    {
        path: '/enroll',
        name: 'Enroll',
        component: Enroll,
    },
    {
        path: '/user',
        component: UserHome,
        children: [
            {
                path: 'home',
                name: 'UserHome',
                component: HomeView,
            },
            {
                path: 'chart',
                name: 'Chart',
                component: Chart,
            },
            {
                path: 'borrow',
                name: 'Borrow',
                component: Borrow,
            },
            {
                path: 'all-records',
                name: 'AllRecords',
                component: AllRecords,
            },
            {
                path: 'user-my-info',
                name: 'user-my-info',
                component: UserMyInfo,
            },
        ]
    },
    {
        path: '/admin',
        component: AdminHome,
        children: [
            {
                path: 'home',
                name: 'AdminHome',
                component: HomeView
            },
            {
                path: 'books',
                name: 'Books',
                component: Books,
            },
            {
                path: 'admin-my-info',
                name: 'admin-my-info',
                component: AdminMyInfo,
            },
            {
                path: 'user-management',
                name: 'UserManagement',
                component: UserManagement,
            },
            {
                path: 'borrow-records',
                name: 'BorrowRecords',
                component: BorrowRecords,
            },
        ]
    },
    {
        path: '/demo',
        name: 'DemoServlet',
        component: DemoServlet
    },
    {
        path: '/test',
        name: 'Test',
        component: Test
    }
];

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes,
});

export default router;
